package com.example.demo.controller;


import com.example.demo.entity.User;
import com.example.demo.entity.UserPreference;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public User getUser(@PathVariable Integer id) {
        return userService.getById(id);
    }

    @PutMapping("/profile")
    public Boolean updateProfile(@RequestBody User user) {
        return userService.updateById(user);
    }

    @GetMapping("/preference/{userId}")
    public UserPreference getPreference(@PathVariable Integer userId) {
        return userService.getPreference(userId);
    }

    @PutMapping("/preference")
    public Boolean updatePreference(@RequestBody UserPreference preference) {
        return userService.updatePreference(preference);
    }
    @GetMapping("/avatar/{userId}")
    public String getAvatarUrl(@PathVariable Integer userId) {
        return userService.getAvatarUrl(userId);
    }
}
